﻿using M_Quality.API.Application.Command.ReinspectionCommand;
using M_Quality.Domain;
using M_Quality.Domain.Dto;
using M_Quality.Repository.Interface;
using MediatR;
using System.Xml.Linq;

namespace M_Quality.API.Application.CommandHandler.ReinspectionCommandHandler
{
    /// <summary>
    /// 查看复检
    /// </summary>
    public class GetByidReinspectionCommandHandler : IRequestHandler<GetByidReinspectionCommand, List<ReDto>>
    {
        /// <summary>
        /// 复检接口
        /// </summary>
        private readonly IReinspectionRepository _Reinspectionrepository;
        /// <summary>
        /// 原料质检接口
        /// </summary>
        private readonly IRawMaterialQualityRepository _rawMaterialQualityRepository;
        public GetByidReinspectionCommandHandler(IReinspectionRepository reinspectionrepository, IRawMaterialQualityRepository rawMaterialQualityRepository)
        {
            _Reinspectionrepository = reinspectionrepository;
            _rawMaterialQualityRepository = rawMaterialQualityRepository;
        }
        public async Task<List<ReDto>> Handle(GetByidReinspectionCommand request, CancellationToken cancellationToken)
        {
            var ReShow = from a in await _Reinspectionrepository.GetAllAsync()
                         join b in await _rawMaterialQualityRepository.GetAllAsync()
                         on a.RawMaterialQualityId equals b.RawMaterialQualityId
                         where a.ReinspectionId == request.ReinspectionId
                         select new ReDto()
                         {
                             RawMaterialQualityId = b.RawMaterialQualityId,
                             QualityNumber = b.QualityNumber,
                             QualityName = b.QualityName,
                             QualityTime = b.QualityTime,
                             Qualityer = b.Qualityer,
                             Supplier = b.Supplier,
                             MaterialNumber = b.MaterialNumber,
                             MaterialName = b.MaterialName,
                             Unit = b.Unit,
                             SpecificationsModel = b.SpecificationsModel,
                             batchNumber = b.batchNumber,
                             Size = b.Size,
                             UnqualifiedQuantity = b.UnqualifiedQuantity,
                             Remark = b.Remark,
                             ReinspectionId = a.ReinspectionId,
                             ReinspectionCode = a.ReinspectionCode,
                             ReinspectionName = a.ReinspectionName,
                             ReinspectionNumber = a.ReinspectionNumber,
                             ReinspectionNote = a.ReinspectionNote,
                             HeGeSarte = a.HeGeSarte,
                             ReinspectionTime = a.ReinspectionTime,
                             ReName = a.ReName,
                             AcceptanceQuantity=b.AcceptanceQuantity
                         };
            return ReShow.ToList();
        }
    }
}
